/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package crawler.common;

import java.net.MalformedURLException;
import java.net.URL;
import org.apache.log4j.Logger;

/**
 *
 * @author LT
 */
public class HTMLUtil {

    private static final Logger logger = Logger.getLogger(HTMLUtil.class);
    public static String toAbsoluteURL(String relative, String full){
        try {
            URL standard = new URL(full);
            String protocol = standard.getProtocol();
            String host =  standard.getHost();
            int port = standard.getPort();
            String file =standard.getFile();
            URL result = new URL(standard, relative);
            return result.toString();
        } catch (MalformedURLException ex) {
            //logger.error("HTMLUtil.toAbsoluteURL:" + ex.getMessage(), ex);
            logger.error("HTMLUtil.toAbsoluteURL: error"+ ex.getMessage() + relative + full);
        }
        return relative;
    }
}
